package com.mud.mudcommune.view.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import com.mud.mudcommune.R;
import com.mud.mudcommune.adapter.OrderAdapter;
import com.mud.mudcommune.view.fragment.twoLevel.ProblemFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class OrderFragment extends Fragment {
    private static OrderFragment fragment = new OrderFragment();
    @BindView(R.id.problem)
    ImageView problem;
    @BindView(R.id.order_list)
    ListView orderList;
    OrderAdapter orderAdapter;
    List list;
    private Unbinder unbinder;

    public static Fragment getInstance() {
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_order, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @OnClick(R.id.problem)
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.problem:
                getFragmentManager().beginTransaction()
                        .hide(OrderFragment.getInstance())
                        .add(R.id.main_frame, ProblemFragment.getInstance())
                        .addToBackStack(null)
                        .commit();
                break;
        }
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        list = new ArrayList();
        list.add("1");
        list.add("2");
        list.add("3");
        FragmentManager fragmentManager = getFragmentManager();
        orderAdapter = new OrderAdapter(getContext(), list, fragmentManager);
        orderList.setAdapter(orderAdapter);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}


